#include <dspSimulator/command/printBRegs.h>
#include <dspSimulator/dspSimulator/dspSimulator.h>

void PrintBRegsCommand::execute(std::string command) {
    auto dspSimulator = dynamic_cast<DSPSimulator *>(m_simulator);
    if (dspSimulator == nullptr) {
        fatalMacro("该模拟器对象不为dsp模拟器对象!");
    }
    auto targetMachine = dspSimulator->m_targetMachine;
    auto dspMachine = std::dynamic_pointer_cast<DspMachine>(targetMachine);
    if (dspMachine == nullptr) {
        fatalMacro("该目标机对象不为dsp目标机对象!");
    }
    for (u32 i = 0; i < static_cast<u32>(RegAKind::NUM_OF_Reg_A); ++i) {
        fprintf(stdout, "%s : %08X\n", RegBName[i],
                *dspMachine->getRegisters()->getReg32ByName(RegBName[i])->getDataPtr());
    }
}

std::shared_ptr<PrintBRegsCommand> PrintBRegsCommand::get(Simulator* dspSimulator) {
    static std::shared_ptr<PrintBRegsCommand> printBRegsCommand;
    if (printBRegsCommand == nullptr) {
        printBRegsCommand = std::make_shared<PrintBRegsCommand>(dspSimulator);
    }
    return printBRegsCommand;
}
